#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
const ll N = 2e5 + 10;
ll a[N];
ll pre[N];
void solve()
{
    ll n;
    cin >> n;
    for (ll i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    ll ans = 0;
    for (ll i = 1; i <= n; i++)
    {
        pre[i] = max(a[i], pre[i - 1] + a[i]);
        ans = max(ans, pre[i]);
    }
    cout << ans;
}
int main()
{
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
